﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.LineVMs
{
    public partial class LineListVM : BasePagedListVM<Line_View, LineSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Line_View>> InitGridHeader()
        {
            return new List<GridColumn<Line_View>>{
                
                this.MakeGridHeader(x => x.Line_WorkshopCode).SetTitle(@Localizer["Page.车间编码"].Value),
                this.MakeGridHeader(x => x.Line_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.Line_LineName).SetTitle(@Localizer["Page.产线名称"].Value),
                this.MakeGridHeader(x => x.Line_ResponsibleId).SetTitle(@Localizer["Page.负责人"].Value),
                this.MakeGridHeader(x => x.Line_Base_Status).SetTitle(@Localizer["Page.产线状态"].Value),
                this.MakeGridHeader(x => x.Line_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Line_View> GetSearchQuery()
        {
            var query = DC.Set<Line>()
                
                .CheckEqual(Searcher.WorkshopCodeId, x=>x.WorkshopCodeId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.LineName, x=>x.LineName)
                .CheckContain(Searcher.ResponsibleId, x=>x.ResponsibleId)
                .CheckEqual(Searcher.Base_Status, x=>x.Base_Status)
                .Select(x => new Line_View
                {
				    ID = x.ID,
                    
                    Line_WorkshopCode = DC.Set<Workshop>().Where(z0 => z0.WorkshopCode == x.WorkshopCodeId).Select(y => y.WorkshopCode).FirstOrDefault(),
                    Line_LineCode = x.LineCode,
                    Line_LineName = x.LineName,
                    Line_ResponsibleId = x.ResponsibleId,
                    Line_Base_Status = x.Base_Status,
                    Line_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Line_View: Line
    {
        
        public string Line_WorkshopCode { get; set; }
        public string Line_LineCode { get; set; }
        public string Line_LineName { get; set; }
        public string Line_ResponsibleId { get; set; }
        public BaseStatusEnum? Line_Base_Status { get; set; }
        public bool Line_IsValid { get; set; }

    }

}